#ifndef _CONDITION_PROCESS_DEFINE_H_
#define _CONDITION_PROCESS_DEFINE_H_

//////////////////////////////////////////////////////////////////////////////////////

#include <assert.h>
#include "DebugPrintf.h"

//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
#ifndef CONDITION_PROCESS_ERROR
	#define CONDITION_PROCESS_ERROR(Condition)    { if (!(Condition)) { goto Exit0; } }
#endif

#ifndef CONDITION_PROCESS_SUCCESS
	#define CONDITION_PROCESS_SUCCESS(Condition)  { if (Condition)    { goto Exit1; } }
#endif

#ifndef CONDITION_DELETE
	#define CONDITION_DELETE(p)				{ if (p) { delete (p); (p) = NULL; } }
#endif

#ifndef CONDITION_DELETE_ARRAY
	#define CONDITION_DELETE_ARRAY(pArray)    { if (pArray) { delete [](pArray); (pArray) = NULL; } }
#endif

#ifndef CONDITION_FCLOSE
	#define CONDITION_FCLOSE(pFile)			{ if (pFile) { fclose(pFile); (pFile) = NULL; } }
#endif

#ifndef CONDITION_ASSERT_EXIT
	#define CONDITION_ASSERT_EXIT(Condition)			{ assert(Condition); if (!(Condition)) { goto Exit0; } }
#endif

#ifndef CONDITION_ASSERT_RETURN_FALSE
	#define CONDITION_ASSERT_RETURN_FALSE(Condition)  { assert(Condition); if (!(Condition)) { return false; } }
#endif

#ifndef CONDITION_ASSERT_RETURN
	#define CONDITION_ASSERT_RETURN(Condition)  { assert(Condition); if (!(Condition)) { return; } }
#endif

#ifndef CONDITION_ASSERT_RETURN_VALUE
	#define CONDITION_ASSERT_RETURN_VALUE(Condition, RetValue)  { assert(Condition); if (!(Condition)) { return (RetValue); } }
#endif

//////////////////////////////////////////////////////////////////////////////////////
#define CONDITION_PROCESS_ERROR_PRINTF0(Condition, szFormat) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF0((szFormat)); \
		goto Exit0; \
	} \
}

#define CONDITION_PROCESS_ERROR_PRINTF1(Condition, szFormat, arg1) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF1((szFormat), (arg1)); \
		goto Exit0; \
	} \
}

#define CONDITION_PROCESS_ERROR_PRINTF2(Condition, szFormat, arg1, arg2) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF2((szFormat), (arg1), (arg2)); \
		goto Exit0; \
	} \
}

#define CONDITION_PROCESS_ERROR_PRINTF3(Condition, szFormat, arg1, arg2, arg3) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF3((szFormat), (arg1), (arg2), (arg3)); \
		goto Exit0; \
	} \
}

#define CONDITION_PROCESS_ERROR_PRINTF4(Condition, szFormat, arg1, arg2, arg3, arg4) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4((szFormat), (arg1), (arg2), (arg3), (arg4)); \
		goto Exit0; \
	} \
}

#define CONDITION_PROCESS_ERROR_PRINTF5(Condition, szFormat, arg1, arg2, arg3, arg4, arg5) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4((szFormat), (arg1), (arg2), (arg3), (arg4), (arg5)); \
		goto Exit0; \
	} \
}
//////////////////////////////////////////////////////////////////////////////////////
#define CONDITION_ASSERT_EXIT_PRINTF0(Condition, szFormat) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF0((szFormat)); assert(Condition); \
		assert(Condition); \
		goto Exit0; \
	} \
}

#define CONDITION_ASSERT_EXIT_PRINTF1(Condition, szFormat, arg1) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF1(szFormat, (arg1));  assert(Condition); \
		assert(Condition); \
		goto Exit0; \
	} \
}

#define CONDITION_ASSERT_EXIT_PRINTF2(Condition, szFormat, arg1, arg2) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF2(szFormat, (arg1), (arg2)); assert(Condition); \
		assert(Condition); \
		goto Exit0; \
	} \
}

#define CONDITION_ASSERT_EXIT_PRINTF3(Condition, szFormat, arg1, arg2, arg3) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF3(szFormat, (arg1), (arg2), (arg3)); \
		assert(Condition); \
		goto Exit0; \
	} \
}

#define CONDITION_ASSERT_EXIT_PRINTF4(Condition, szFormat, arg1, arg2, arg3, arg4) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4)); \
		assert(Condition); \
		goto Exit0; \
	} \
}

#define CONDITION_ASSERT_EXIT_PRINTF5(Condition, szFormat, arg1, arg2, arg3, arg4, arg5) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4), (arg5)); \
		assert(Condition); \
		goto Exit0; \
	} \
}
//////////////////////////////////////////////////////////////////////////////////////
#define CONDITION_ASSERT_RETURN_FALSE_PRINTF0(Condition, szFormat) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF0((szFormat)); \
		assert(Condition); \
		return false; \
	} \
}

#define CONDITION_ASSERT_RETURN_FALSE_PRINTF1(Condition, szFormat, arg1) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF1(szFormat, (arg1)); assert(Condition); \
		assert(Condition); \
		return false; \
	} \
}

#define CONDITION_ASSERT_RETURN_FALSE_PRINTF2(Condition, szFormat, arg1, arg2) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF2(szFormat, (arg1), (arg2)); \
		assert(Condition); \
		return false; \
	} \
}

#define CONDITION_ASSERT_RETURN_FALSE_PRINTF3(Condition, szFormat, arg1, arg2, arg3) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF3(szFormat, (arg1), (arg2), (arg3)); \
		assert(Condition); \
		return false; \
	} \
}

#define CONDITION_ASSERT_RETURN_FALSE_PRINTF4(Condition, szFormat, arg1, arg2, arg3, arg4) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4)); \
		assert(Condition); \
		return false; \
	} \
}

#define CONDITION_ASSERT_RETURN_FALSE_PRINTF5(Condition, szFormat, arg1, arg2, arg3, arg4, arg5) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4), (arg5)); \
		assert(Condition); \
		return false; \
	} \
}
//////////////////////////////////////////////////////////////////////////////////////
#define CONDITION_ASSERT_RETURN_PRINTF0(Condition, szFormat) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF0((szFormat)); \
		assert(Condition); \
		return; \
	} \
}

#define CONDITION_ASSERT_RETURN_PRINTF1(Condition, szFormat, arg1) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF1(szFormat, (arg1)); assert(Condition); \
		assert(Condition); \
		return; \
	} \
}

#define CONDITION_ASSERT_RETURN_PRINTF2(Condition, szFormat, arg1, arg2) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF2(szFormat, (arg1), (arg2)); \
		assert(Condition); \
		return; \
	} \
}

#define CONDITION_ASSERT_RETURN_PRINTF3(Condition, szFormat, arg1, arg2, arg3) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF3(szFormat, (arg1), (arg2), (arg3)); \
		assert(Condition); \
		return; \
	} \
}

#define CONDITION_ASSERT_RETURN_PRINTF4(Condition, szFormat, arg1, arg2, arg3, arg4) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4)); \
		assert(Condition); \
		return; \
	} \
}

#define CONDITION_ASSERT_RETURN_PRINTF5(Condition, szFormat, arg1, arg2, arg3, arg4, arg5) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4), (arg5)); \
		assert(Condition); \
		return; \
	} \
}

/////////////////////////////////////////////////////////////////////////////////////////
#define CONDITION_ASSERT_RETURN_VALUE_PRINTF0(Condition, RetValue, szFormat) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF0((szFormat)); \
		assert(Condition); \
		return (RetValue); \
	} \
}

#define CONDITION_ASSERT_RETURN_VALUE_PRINTF1(Condition, RetValue, szFormat, arg1) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF1(szFormat, (arg1)); assert(Condition); \
		assert(Condition); \
		return (RetValue); \
	} \
}

#define CONDITION_ASSERT_RETURN_VALUE_PRINTF2(Condition, RetValue, szFormat, arg1, arg2) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF2(szFormat, (arg1), (arg2)); \
		assert(Condition); \
		return (RetValue); \
	} \
}

#define CONDITION_ASSERT_RETURN_VALUE_PRINTF3(Condition, RetValue, szFormat, arg1, arg2, arg3) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF3(szFormat, (arg1), (arg2), (arg3)); \
		assert(Condition); \
		return (RetValue); \
	} \
}

#define CONDITION_ASSERT_RETURN_VALUE_PRINTF4(Condition, RetValue, szFormat, arg1, arg2, arg3, arg4) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4)); \
		assert(Condition); \
		return (RetValue); \
	} \
}

#define CONDITION_ASSERT_RETURN_VALUE_PRINTF5(Condition, RetValue, szFormat, arg1, arg2, arg3, arg4, arg5) \
{ \
	if (!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4), (arg5)); \
		assert(Condition); \
		return (RetValue); \
	} \
}

/////////////////////////////////////////////////////////////////////////////////////////
#define CONDITION_ERROR_PRINTF0(Condition, szFormat) \
{ \
	if(!(Condition)) \
	{ \
		DEBUG_PRINTF0(szFormat); \
	} \
}

#define CONDITION_ERROR_PRINTF1(Condition, szFormat, arg1) \
{ \
	if(!(Condition)) \
	{ \
		DEBUG_PRINTF1(szFormat, (arg1)); \
	} \
}

#define CONDITION_ERROR_PRINTF2(Condition, szFormat, arg1, arg2) \
{ \
	if(!(Condition)) \
	{ \
		DEBUG_PRINTF2(szFormat, (arg1), (arg2)); \
	} \
}

#define CONDITION_ERROR_PRINTF3(Condition, szFormat, arg1, arg2, arg3) \
{ \
	if(!(Condition)) \
	{ \
		DEBUG_PRINTF3(szFormat, (arg1), (arg2), (arg3)); \
	} \
}

#define CONDITION_ERROR_PRINTF4(Condition, szFormat, arg1, arg2, arg3, arg4) \
{ \
	if(!(Condition)) \
	{ \
		DEBUG_PRINTF4(szFormat, (arg1), (arg2), (arg3), (arg4)); \
	} \
}

#define CONDITION_ERROR_PRINTF5(Condition, szFormat, arg1, arg2, arg3, arg4, arg5) \
{ \
	if(!(Condition)) \
	{ \
		DEBUG_PRINTF5(szFormat, (arg1), (arg2), (arg3), (arg4), (arg5)); \
	} \
}

#endif
